/**
 * variant 多态 ad-hoc:
 * std::visit 获取到 std::variant 实际存储的类型的时间复杂度为 O(1)，性能不会随着 std::variant 中类型的增多而降低
 */
#include <iostream>
#include <variant>
#include <vector>


struct Triangle {
    void Draw() const {
        std::cout << "Triangle" << std::endl;
    }
};

struct Circle {
    void Draw() const {
        std::cout << "Circle" << std::endl;
    }
};


std::variant<double, bool, std::string> var;

struct {
    void operator()(int) { std::cout << "int!\n"; }

    void operator()(std::string const &) { std::cout << "string!\n"; }
} visitor;


int main() {
    using Draw = std::variant<Triangle, Circle>;
    Draw draw;
    std::vector<Draw> draws{Triangle{}, Circle{}, Triangle{}};
    auto DrawVisitor = [](const auto &t) {
        t.Draw();
    };
    for (const auto &item: draws) {
        std::visit(DrawVisitor, item);
    }

    std::visit(visitor, var);
}